package com.example.asus.testskip.DGPhone.phone;

import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.IBinder;
import android.telephony.TelephonyManager;
import android.view.KeyEvent;

import com.android.internal.telephony.ITelephony;

import java.lang.reflect.Method;

/* renamed from: dg.ca.com.DGPhone.phone.Utils */
public class Utils {
    public static boolean hasGingerbread() {
        return VERSION.SDK_INT >= 9;
    }

    public static void sendEndCallBroadCast(Context ctx) {
        Intent i = new Intent();
        i.setAction(OverLayActivity.ACTION_END_CALL);
        ctx.sendBroadcast(i);
    }

    public static synchronized void endCall(Context ctx) {
        synchronized (Utils.class) {
            TelephonyManager mTelMgr = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
            try {
                Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
                IBinder binder = (IBinder) method.invoke(null, new Object[]{Context.TELEPHONY_SERVICE});
                ITelephony telephony = ITelephony.Stub.asInterface(binder);
                telephony.endCall();
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("Fail to answer ring call.");
            }
        }
        return;
    }

    public static synchronized void answerRingingCall(Context ctx) {
        synchronized (Utils.class) {
            try {
                Intent localIntent1 = new Intent("android.intent.action.HEADSET_PLUG");
                localIntent1.addFlags(1073741824);
                localIntent1.putExtra("state", 1);
                localIntent1.putExtra("microphone", 1);
                localIntent1.putExtra("name", "Headset");
                ctx.sendOrderedBroadcast(localIntent1, "android.permission.CALL_PRIVILEGED");
                Intent localIntent2 = new Intent("android.intent.action.MEDIA_BUTTON");
                localIntent2.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(0, 79));
                ctx.sendOrderedBroadcast(localIntent2, "android.permission.CALL_PRIVILEGED");
                Intent localIntent3 = new Intent("android.intent.action.MEDIA_BUTTON");
                localIntent3.putExtra("android.intent.extra.KEY_EVENT", new KeyEvent(1, 79));
                ctx.sendOrderedBroadcast(localIntent3, "android.permission.CALL_PRIVILEGED");
                Intent localIntent4 = new Intent("android.intent.action.HEADSET_PLUG");
                localIntent4.addFlags(1073741824);
                localIntent4.putExtra("state", 0);
                localIntent4.putExtra("microphone", 1);
                localIntent4.putExtra("name", "Headset");
                ctx.sendOrderedBroadcast(localIntent4, "android.permission.CALL_PRIVILEGED");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return;
    }


    public static synchronized void answerCall(Context ctx) {
        synchronized (Utils.class) {
            try {
                Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class);
                IBinder binder = (IBinder) method.invoke(null, new Object[]{Context.TELEPHONY_SERVICE});
                ITelephony telephony = ITelephony.Stub.asInterface(binder);
                telephony.answerRingingCall();
            } catch (Exception e) {
                e.printStackTrace();
                //4.1系统以后的电话接听
                answerRingingCall(ctx);
            }
        }
        return;
    }

    public static boolean hasHoneycombMR2() {
        return VERSION.SDK_INT >= 13;
    }
}
